package cn.sms.basic.controller;

import cn.sms.basic.exception.BusinessException;
import cn.sms.basic.service.IVerifycodeService;
import cn.sms.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {
    @Autowired
    private IVerifycodeService iVerifycodeService;

    @PostMapping("/smsCode")
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> phones){
        try {
            String phone = phones.get("phone");
            String type = phones.get("type");
            iVerifycodeService.sendSmsCode(phone,type);
            return AjaxResult.me();
        } catch (BusinessException e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试");
        }
    }
}
